<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *客户列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'渠道客户数据'),
);
//客户列表
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$types=$this->from_type;
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$between=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$fwparams=$fsparams=$params;
	$fwparams['fromworkerid >']=0;
	$fsparams['storeid >']=0;
	if(!$between){
		$fwparams['createtime >']=0;
		$fsparams['createtime >']=0;
	}else{
		$fwparams['createtime between']=$between;
		$fsparams['createtime between']=$between;
	}
	$list=array();
	if($types){
		foreach($types as $k=>$v){
			$params['from_type']=$fwparams['from_type']=$fsparams['from_type']=$k;
			$item=array();
			$item['title']=$v;
			$item['memberall']=pdo_count('jy_zhongyi_user',$params);
			$item['fwnum']=pdo_count('jy_zhongyi_user',$fwparams);
			$item['fsnum']=pdo_count('jy_zhongyi_user',$fsparams);
			$list[]=$item;
		}
	}
	$heji=array('title'=>'合计');
	foreach($list as $v){
		$heji['memberall'] +=$v['memberall'];
		$heji['ordernum'] +=$v['ordernum'];
		$heji['orderfee'] +=$v['orderfee'];
		$heji['yuenum'] +=$v['yuenum'];
		$heji['yuefee'] +=$v['yuefee'];
	}
	$list[]=$heji;
	$return['list']=$list;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'类型','type'=>'string'),
			array('name'=>'memberall','title'=>'客户数','type'=>'string'),
			array('name'=>'fwnum','title'=>'来源大夫','type'=>'string'),
			array('name'=>'fsnum','title'=>'来源门店','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'from_type','width'=>15,'title'=>'渠道来源','type'=>'radio','options'=>'from_type'),
			array('name'=>'createtime','width'=>15,'title'=>'时间段','type'=>'time_range')
		),
	);
	$return['from_type']=$this->from_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	//客户列表
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$types=$this->from_type;
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$between=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$fwparams=$fsparams=$params;
	$fwparams['fromworkerid >']=0;
	$fsparams['storeid >']=0;
	if(!$between){
		$fwparams['createtime >']=0;
		$fsparams['createtime >']=0;
	}else{
		$fwparams['createtime between']=$between;
		$fsparams['createtime between']=$between;
	}
	$list=array();
	if($types){
		foreach($types as $k=>$v){
			$params['from_type']=$fwparams['from_type']=$fsparams['from_type']=$k;
			$item=array();
			$item['title']=$v;
			$item['memberall']=pdo_count('jy_zhongyi_user',$params);
			$item['fwnum']=pdo_count('jy_zhongyi_user',$fwparams);
			$item['fsnum']=pdo_count('jy_zhongyi_user',$fsparams);
			$list[]=$item;
		}
	}
	$heji=array('title'=>'合计');
	foreach($list as $v){
		$heji['memberall'] +=$v['memberall'];
		$heji['ordernum'] +=$v['ordernum'];
		$heji['orderfee'] +=$v['orderfee'];
		$heji['yuenum'] +=$v['yuenum'];
		$heji['yuefee'] +=$v['yuefee'];
	}
	$list[]=$heji;
	$header=array(
		'title'=>'类型',
		'memberall'=>'客户数',
		'fwnum'=>'来源大夫',
		'fsnum'=>'来源门店',
	);
	model('core/tools')->export2excel($header,$list,'渠道数据');
}